package com.sx.pipeline.custom.dialog

import android.content.Context
import android.text.SpannableStringBuilder
import android.text.method.LinkMovementMethod
import android.view.View
import android.widget.TextView
import com.lxj.xpopup.core.BottomPopupView
import com.lxj.xpopup.core.CenterPopupView
import com.sx.pipeline.R
import com.sx.pipeline.utils.setClickSpan
import io.rong.callkit.util.SPUtils

class DialogAgreement(context: Context,var agreement:(Int)->Unit,var confirm:() ->Unit,var cancel:() ->Unit) : CenterPopupView(context) {
    override fun getImplLayoutId(): Int {
        return R.layout.dialog_agreement
    }

    override fun onCreate() {
        super.onCreate()
        val userAgreement = "《用户协议》"
        val privateAgreement = "《隐私协议》"
        val contain =
            "欢迎您使用管建宝APP\n\n1、保护用户隐私是管建宝的一项基本政策，管建宝不会泄露您的个人信息;\n\n2、为了更好的提供浏览推荐、发布内容等使用相关服务体验，我们会根据您使用服务的具体功能需要，收集必要的用户信息(如申请设备信息、存储、位置、相机等相关权限);\n\n3、您可阅读完整版"
        val contain2 =
            userAgreement + "、" + privateAgreement + "了解我们申请使用相关权限的情况，已经对您个人隐私的保护措施;"
        val builder = SpannableStringBuilder(contain + contain2)
        builder.setClickSpan(contain.length,
            userAgreement.length,
            textColor = context.getColor(R.color.color_0188ff),
            clickCallBack = {
                //用户协议
                agreement.invoke(2)
            })
        builder.setClickSpan(contain.length + userAgreement.length + 1,
            privateAgreement.length,
            textColor = context.getColor(R.color.color_0188ff),
            clickCallBack = {
                //隐私协议
                agreement.invoke(1)
            })

        findViewById<TextView>(R.id.content).setMovementMethod(LinkMovementMethod.getInstance());
        findViewById<TextView>(R.id.content).setText(builder)
        findViewById<TextView>(R.id.xy_refuse).setOnClickListener {
            cancel.invoke()
        }
        findViewById<View>(R.id.xy_agree).setOnClickListener {
            //同意
            SPUtils.put(context,"firstStart",true)
            confirm.invoke()
            dismiss()
        }
    }
}
